package org.example.mybatisdemo.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.example.mybatisdemo.Model.UserInfo;

import java.util.List;

@Mapper
public interface UserInfoMapper {
//    方法实现
    @Select("select * from userinfo")
//    方法的声明
    List<UserInfo> queryUserInfos();

    @Select("select * from userinfo where id = #{id}")
    UserInfo queryUserInfo(@Param("id")Integer id);

    @Select("select * from userinfo where id = #{param1}")
    UserInfo queryUserInfoIdAndName(@Param("id1")Integer id);
//                                                    是and！！！！不是，
    @Select("select * from userinfo where id = #{param1} and username = #{param2}")
    UserInfo queryUserInfoIdAndName2(@Param("id1") Integer id,@Param("name2") String name);

//    把问号变为参数
//    @Insert("insert into userinfo (username,`password`,age,gender,phone) values(?,?,?,?)")
    @Insert("insert into userinfo (username,`password`,age,gender,phone) " +
            "values(#{username},#{password},#{gender},#{phone})")
    Integer insert(UserInfo userInfo);
}
